﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using Sy.DbHelperA;

using System.Net.Mail;
using Microsoft.Exchange.WebServices;
using Microsoft.Exchange.WebServices.Data;
using System.Web;
using System.IO;

namespace EmailDS
{

    public partial class Form1 : Form
    {

        public ExchangeService service = new ExchangeService();

        public string FFJEmail;
        public string FHour;
        public string FMIN;
        public string FS;



        System.Timers.Timer timer = new System.Timers.Timer();
        public Form1()
        {


            InitializeComponent();
        }

        private void butStart_Click(object sender, EventArgs e)
        {


            FFJEmail = textBox4.Text;

            textBox1.Enabled = false;
            textBox2.Enabled = false;
            textBox3.Enabled = false;

            FHour = textBox1.Text;
            FMIN = textBox2.Text;
            FS = textBox3.Text;

        

            timer.Enabled = true;
            
            timer.Interval = 1000;//执行间隔时间,单位为毫秒  
            timer.Start();
            // 指定每天时间1执行
            timer.Elapsed += new System.Timers.ElapsedEventHandler(Timer1_Elapsed);
            timer.AutoReset = true; //设置一直执行(true)
            timer1.Enabled = true ; //是否执行System.Timers.Timer.Elapsed事件

            butStart.Enabled = false;


        }


        private void Timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            // 得到intHour,intMinute,intSecond，是当前系统时间  
            int intHour = e.SignalTime.Hour;
            int intMinute = e.SignalTime.Minute;
            int intSecond = e.SignalTime.Second;
            


            //    //自己设置hour,minuter,second,到设定的时间就开始执行程序  
            if (intMinute.ToString() == "1"  && intHour.ToString() == "2"  && intSecond.ToString() == "1")
                {

                    //MessageBox.Show("123");

                    BIDBJ rs = new BIDBJ();
                    rs.setBIDBJ();

                    MAGGZ ma = new MAGGZ();
                    ma.setMAGGZ();
              
                 }

        }

        private void butStop_Click(object sender, EventArgs e)
        {
            System.Timers.Timer timer = new System.Timers.Timer();
            timer.Enabled = false;
            timer.Stop();
            //textBox1.Enabled = true;
            //textBox2.Enabled = true;
            //textBox3.Enabled = true;
            //textBox4.Enabled = true;
            butStart.Enabled = true;
        }






        private void Form1_Load_1(object sender, EventArgs e)
        {
            textBox1.Text = "2";
            textBox2.Text = "1";
            textBox3.Text = "1";

            textBox1.Enabled = false;
            textBox2.Enabled = false;
            textBox3.Enabled = false;
            
            string a, b;
            a = "";
            b = "";
            foreach (string str in System.IO.File.ReadAllLines("C:\\K3\\Mail.txt", Encoding.Default))
            {

                a = str + "\r\n";
                b = b + a;
            }
            butStart_Click(null, EventArgs.Empty);
            richTextBox1.Text = b;

           

        }

        }

    }

